package cn.net.isir.service2;

import cn.net.isir.dao.CategoryDao;
import cn.net.isir.dao.GoodsDao;
import cn.net.isir.dao.ShopUserDao;
import cn.net.isir.entity.Category;
import cn.net.isir.entity.Goods;
import cn.net.isir.entity.ShopUser;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @author liuxubo
 * @filename GalleryService.java
 * @package cn.net.isir.service2
 * @email lxb@isir.net.cn
 * @date 2018/12/28
 * @comment
 * @since 1.8
 */
@Service
public class GalleryService {

    @Resource
    private ShopUserDao shopUserDao;
    @Resource
    private CategoryDao categoryDao;
    @Resource
    private GoodsDao goodsDao;

    /**
     * 获取某用户下的所有菜品
     *
     * @param userId 用户
     * @param name 菜品名称
     * @return 获取菜品列表
     */
    public List<Goods> getAllShopGoods(String userId, String name) {
        List<Goods> goodsList = new ArrayList<>();
        ShopUser shopUser = new ShopUser();
        shopUser.setUserId(userId);
        for (ShopUser su : shopUserDao.selectList(shopUser)) {
            Category category = new Category();
            category.setShopId(su.getShopId());
            for (Category c : categoryDao.selectList(category)) {
                Goods goods = new Goods();
                goods.setCategoryId(c.getId());
                goods.setName(name);
                goodsList.addAll(goodsDao.selectList(goods));
            }
        }
        return goodsList;
    }
}
